﻿//using System;
//using System.Collections.Generic;
//using System.IO;
//using System.Linq;
//using System.Net.Http.Headers;
//using System.Reflection;
//using System.Text;
//using System.Threading.Tasks;
////using System.Windows;
//using Autodesk.AutoCAD.ApplicationServices;
//using Autodesk.AutoCAD.EditorInput;
//using Autodesk.AutoCAD.Runtime;

//using CAD.Service;

//namespace CAD.LoadX
//{
//    public class LoadCommand
//    {
//        private Action cmd;

//        public static string assemblyPath = Assembly.GetExecutingAssembly().Location;
//        //public static string assemblyDir = Path.GetDirectoryName(assemblyPath) + "\\";
//        public static string assemblyDir = "D:\\WORKSPACE\\CODE_CAD\\CAD.Demo\\bin\\Debug\\";

//        [CommandMethod("DE")]
//        public void ReloadX()
//        { 
//            string jsonPath = $"{assemblyDir}cmdinfo.json";
//            string jsonStr = jsonPath.ReadFileText(Encoding.UTF8);
//            CmdInfo cmdInfo = jsonStr.ToEntity<CmdInfo>().First();
             
//            //编辑器
//            Editor editor = Application.DocumentManager.MdiActiveDocument.Editor;
//            editor.WriteMessage($"\n dll-path:{jsonPath} \n ");//命令行文字

//            #region
//            string dllName = cmdInfo.dllName;
//            string namespaceName = cmdInfo.namespaceName;
//            string className = cmdInfo.className;
//            string methodName = cmdInfo.methodName;

//            //dllName = "CAD.Demo.dll";
//            //namespaceName = "CAD.Demo";
//            //className = "HelloCommand";
//            //methodName = "CadHello";
//            #endregion


//            #region  fix 反射方法 通过类和方法名称 获得功能DLL内实体的方法实例

//            var adapterFileInfo = new FileInfo(Assembly.GetExecutingAssembly().Location);
//            var targetFilePath = Path.Combine(adapterFileInfo.DirectoryName, dllName);
//            var targetAssembly = Assembly.Load(File.ReadAllBytes(targetFilePath));
//            var targetType = targetAssembly.GetType($"{namespaceName}.{className}");
//            //if (targetType == null) { MessageBox.Show("targetType==null", "error++"); return; }
//            var targetMethod = targetType.GetMethod(methodName);
//            var targetObject = Activator.CreateInstance(targetType);

//            object[] constuctParams = new object[] { };
//            cmd = () => targetMethod.Invoke(targetObject, constuctParams);

//            try
//            {
//                cmd?.Invoke();
//            }
//            catch (System.Exception ex)
//            {
//               System.Windows.MessageBox.Show(ex.Message, "error++");
//            }

//            #endregion




//        }


//    }


//}

////json
///*
  
// {
//  "dllName": "CAD.Demo.dll",
//  "namespaceName": "CAD.Demo",
//  "className": "HelloCommand",
//  "methodName": "CadDbText"
//}
  
// */